package object3;

/**
 * 代码块
 * [修饰符]{
 *     代码
 * };
 */
public class CodeBlock01 {

    public static void main(String[] args) {

        /*
            1)修饰符可选，要写的话也只能写static
            2)代码块分为两类，使用static修饰的叫静态代码块，没有static修饰的，叫普通代码块
            3)逻辑语句可以为任意逻辑语句
            4)结尾;号可省略
         */
        Movie movie = new Movie("星际穿越");
        /*
            电影屏幕打开...
            广告开始...
            电影正式开始...
            Movie(String name) 被调用...
         */
        System.out.println("============");
        Movie movie1 = new Movie("唐探3", 100, "陈思诚");
        /*
            电影屏幕打开...
            广告开始...
            电影正式开始...
            Movie(String name, double price, String director) 被调用...
         */

    }
}

class Movie {

    private String name;

    private double price;

    private String director;

    /*
        创建对象时优先会调用代码块的内容，代码块的调用顺序优先于构造器
     */
    {
        System.out.println("电影屏幕打开...");
        System.out.println("广告开始...");
        System.out.println("电影正式开始...");
    }

    public Movie(String name) {
        System.out.println("Movie(String name) 被调用...");
        this.name = name;
    }

    public Movie(String name, double price) {
        System.out.println("Movie(String name, double price) 被调用...");
        this.name = name;
        this.price = price;
    }

    public Movie(String name, double price, String director) {
        System.out.println("Movie(String name, double price, String director) 被调用...");
        this.name = name;
        this.price = price;
        this.director = director;
    }
}